import { getMaterialRecommendList, getCaseRecommendList } from '../../api/index'

Component({
  properties: {
    recommend: {
      type: Object,
      value: {
        videoBanners: [],
        materialBanners: [],
        caseBanners: [],
        caseList: [],
        materialList: [],
        videoList: []
      }
    }
  },
  observers: {
    // onshowTime (val) {
    //   if (val && !this.data.isFirst.index) {
    //     this.getCaseList()
    //   }
    // }
  },
  data: {
    // videoList: []
  },
  methods: {
    seedetail ({ currentTarget: { dataset: { item } } }) {
      wx.$nav.navigateTo(`/pages/caseDetail/index?id=${item.materialCaseId}`)
    },
    getLength ({ currentTarget: { dataset: { item, index } }, detail: { duration } }) {
      let time = duration * 60
      let minute = parseInt(time / 60)
      let second = parseInt(time % 60)
      let minuteStr = ''
      let secondStr = ''
      if (minute < 9) {
        minuteStr = `0${minute}`
      } else {
        minuteStr = minute
      }
      if (second < 9) {
        secondStr = `0${second}`
      } else {
        secondStr = second
      }
      item.duration = `${minuteStr}:${secondStr}`
      let key = `recommend.videoList[${index}]`
      this.setData({ [key]: item })
    },
    change ({ detail }) {
      let index = this.data.recommend.caseList.findIndex(row => row.materialCaseId === detail.materialCaseId)
      if (index > -1) {
        let changeKey = `caseList[${index}]`
        this.setData({
          [changeKey]: detail
        })
      }
    },
  },
})